<template>
  <div>
    <!--列表-->
    <el-table
      ref="table"
      v-loading="tableLoad"
      :data="tableData"
      fit
      highlight-current-row
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="sampleNum" label="样品编号"> </el-table-column>
      <el-table-column prop="orderNum" label="委托单号"> </el-table-column>
      <el-table-column prop="sampleName" label="样品名称"> </el-table-column>
      <el-table-column prop="inspectedUnit" label="受检单位"> </el-table-column>
      <el-table-column prop="detectionItemName" label="检测项目" />
      <el-table-column prop="count" label="单份容量" />
      <el-table-column label="操作" width="180">
        <template slot-scope="{ row }">
          <div class="base-table-operation">
            <el-link v-rights="'Query'" type="primary" @click="selUnit(row)"
              >查看</el-link
            >
            <!-- <el-link
              v-if="systemType == 'thirdparty'"
              type="primary"
              @click="quoteLabel(row)"
              >配置模板</el-link
            > -->
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <!--BasePagination
      :total="pagination.total"
      :current-page="pagination.pageIndex"
      :page-count="pagination.pageCount"
      @changePage="changePage"
    /-->

    <SampleRegistrationDialog
      v-if="dialogFormVisible"
      ref="SampleRegistrationDialog"
      :dialog-form-visible.sync="dialogFormVisible"
      :sample-registration-id.sync="sampleRegistrationId"
      :module-enable-entrust="moduleEnableEntrust"
      :read-only.sync="readOnly"
    />
    <QuoteLabelDialog
      v-if="quoteLabelVisible"
      ref="QuoteLabelDialog"
      :quote-label-visible.sync="quoteLabelVisible"
      :sample-registration-id.sync="sampleRegistrationId"
      @closeQuoteLabel="closeQuoteLabel"
    />
  </div>
</template>

<script>
import QuoteLabelDialog from "./QuoteLabelDialog.vue";
import { getConfigByKey } from "../../../api/System/SystemDict";
import { getSampleRegistrationList } from "../../../api/SampleManage/SampleRegistration";
import SampleRegistrationDialog from "./SampleRegistrationDialog.vue";
export default {
  name: "SampleFinished",
  components: { SampleRegistrationDialog, QuoteLabelDialog },
  props: {
    moduleEnableEntrust: {
      type: Boolean,
      default: false,
    },
    pagination: {
      type: Object,
      default: function() {
        return { pageIndex: 1, pageSize: 10, total: 0 };
      },
    },
    filterForm: {
      type: Object,
      default() {
        return { orderNum: "", tableWhetherEnum: 1 };
      },
    },
  },
  data() {
    return {
      systemType: "",
      readOnly: false,
      dialogFormVisible: false,
      quoteLabelVisible: false,
      loading: false,
      // 样品登记id
      sampleRegistrationId: "",
      tableLoad: false,
      tableData: [],
      tableDatas: [],
    };
  },
  computed: {},
  watch: {
    "pagination.pageIndex"(newV, oldV) {
      this.getList();
    },
  },
  created() {
    // 查询字典表判断系统类型
    getConfigByKey("SystemType").then((res) => {
      this.systemType = res.data[0].value;
    });
    this.getList();
  },
  methods: {
    // 关闭
    closeQuoteLabel() {
      this.getList();
    },
    // 引用实验记录单
    quoteLabel(row) {
      this.sampleRegistrationId = row.id;
      this.quoteLabelVisible = true;
    },
    // 样品登记
    selUnit(row) {
      this.sampleRegistrationId = row.id;
      this.readOnly = true;
      this.dialogFormVisible = true;
    },
    handleSelectionChange(val) {
      this.tableDatas = val;
    },
    getList(flag) {
      if (flag) {
        this.pagination.pageIndex = 1;
      }
      this.loading = true;
      getSampleRegistrationList({ ...this.filterForm, ...this.pagination })
        .then((res) => {
          this.tableData = res.data.dataList ? res.data.dataList : [];
          this.pagination.total = res.data.total;
          this.$emit("update:total", res.data.total);
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
  },
};
</script>
